#include "Date.h"

bool Date::operator<(const Date &d) const
{
    if (m_year < d.m_year)
    {
        return true;
    }
    else if (m_year == d.m_year && m_month < d.m_month)
    {
        return true;
    }
    else if (m_year == d.m_year && m_month == d.m_month && m_day < d.m_day)
    {
        return true;
    }
    else
    {
        return false;
    }
}

Date &Date::operator+=(int day)
{
    m_day += day;
    int days = getMonthDay(m_year, m_month);
    while (m_day > days)
    {
        days = getMonthDay(m_year, m_month);
        m_day -= days;
        m_month++;
        if (m_month == 13)
        {
            m_year++;
            m_month = 1;
        }
    }
    return *this;
}

Date &Date::operator-=(int day)
{
    m_day -= day;

    while (m_day < 0)
    {
        m_month--;
        if (m_month == 0)
        {
            m_month = 12;
            m_year--;
        }
        int days = getMonthDay(m_year, m_month);
        m_day += days;
    }
    return *this;
}

int Date::operator-(const Date &d) const
{
    int count = 0;
    Date max = *this > d ? *this : d;
    Date min = *this < d ? *this : d;
    while (min != max)
    {
        min += 1;
        count++;
    }
    return count;
}
